#include <iostream>
#include <cstring>
using namespace std;

/*
    类的成员函数可以写在类里面，也可以写在类外
*/

class Cat
{
public:
    void catchMouse();
    void playMagic();
    void setAttr(int a, char *n, float w);
    void show();

private:
    int age;
    char name[32];
    float weight;
};

// 成员函数写在类外 .语法 类名::成员函数名
void Cat::catchMouse()
{
    cout << "抓老鼠" << endl;
}
void Cat::playMagic()
{
    cout << "玩魔方" << endl;
}
void Cat::setAttr(int a, char *n, float w)
{
    age = a;
    strcpy(name, n);
    weight = w;
}
void Cat::show()
{
    cout << "年龄：" << age << endl;
    cout << "名字：" << name << endl;
    cout << "体重：" << weight << endl;
}
int main()
{
    // 使用栈空间
    Cat c1;
    // 使用堆空间
    c1.catchMouse();
    char name1[32] = "小猫";
    c1.setAttr(3, name1, 0.5);
    c1.show();
    Cat *c2 = new Cat;
    c2->playMagic();
    char name2[32] = "大咩";
    c2->setAttr(5, name2, 0.8);
    c2->show();

    return 0;
}